<?php
class TareasController extends AppController {
	
	var $name = 'Tareas';
	var $helpers = array('Html', 'Form');

	function mistareas() {
		
	}
	
	function index() {
		$this->Tarea->recursive = 1;
		$this->set('tareas', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Tarea', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('tarea', $this->Tarea->read(null, $id));
	}

	function add() {
		$empresas = $this->Tarea->Empresa->find('list');
		$this->set(compact('empresas'));
		$instituciones = $this->Tarea->Institucion->find('list');
		$this->set(compact('instituciones'));
		if (!empty($this->data)) {
			$this->Tarea->create();
			if ($this->Tarea->save($this->data)) {
				$this->Session->setFlash(__('The Tarea has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Tarea could not be saved. Please, try again.', true));
			}
		}else{
			//$this->set('listaEmpresas', $this->Tarea->Empresa->generateList(null,null,null,'{n}.Empresa.id','{n}.Empresa.nombre'));
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Tarea', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Tarea->save($this->data)) {
				$this->Session->setFlash(__('The Tarea has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Tarea could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Tarea->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Tarea', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Tarea->del($id)) {
			$this->Session->setFlash(__('Tarea deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Tarea could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}
	
}
?>
